package com.example.neusoftfood_c213_zhong.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.neusoftfood_c213_zhong.R;
import com.example.neusoftfood_c213_zhong.activity.FoodListActivity;
import com.example.neusoftfood_c213_zhong.beans.Shop;
import com.example.neusoftfood_c213_zhong.common.Constants;
import com.squareup.picasso.Picasso;

import java.util.List;

public class ShopAdapter extends RecyclerViewAdapter<ShopAdapter.ShopViewHolder>{

    public ShopAdapter(Context context, List data, int layoutResource) {
        super(context, data, layoutResource);
    }

    public void onBindViewHolder(ShopAdapter.ShopViewHolder shopViewHolder, int i) {
        final Shop shop = (Shop) data.get(i);
        shopViewHolder.res_name.setText(shop.getShopname());
        shopViewHolder.res_address.setText(shop.getAddress());
        shopViewHolder.res_bar.setRating(shop.getLevel());
        Picasso.with(context).load(Constants.BASE_URL+shop.getPic()).into(shopViewHolder.image);
        shopViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, FoodListActivity.class);
                intent.putExtra("shop_id", shop.getShop_id());
                intent.putExtra("res_name",shop.getShopname());
                intent.putExtra("res_address", shop.getAddress());
                intent.putExtra("res_pic",shop.getPic());
                intent.putExtra("res_bar", shop.getLevel());
                intent.putExtra("res_phone",shop.getPhonenum());

                context.startActivity(intent);
            }
        });
    }





    public static class ShopViewHolder extends RecyclerView.ViewHolder {
        RatingBar res_bar;
        Button button;
        TextView res_name, res_address,res_phone;
        ImageView image;
        public ShopViewHolder(View view) {
            super(view);
            image = (ImageView) view.findViewById(R.id.pic);
            res_name = (TextView) view.findViewById(R.id.shop_name);
            res_bar = (RatingBar) view.findViewById(R.id.food_ratingBar);
            res_address = (TextView) view.findViewById(R.id.address);
            res_phone = (TextView)view.findViewById(R.id.shop_phone);
            button = (Button)view.findViewById(R.id.btninto);
        }
    }
}
